package sniff.pack;

import control.SystemUIControl;

public class MyIPv4Packet extends CommonIPPacket {
	protected String version;
	protected int headLen;
	protected String ds;
	protected String id;
	protected int mf;
	protected int df;
	protected int fragmentOffset;
	protected int timeToLive;
	protected String headerCheckNum;
	protected CommonIPChildPacket childPacket;

	public MyIPv4Packet() {

	}

	public MyIPv4Packet(String sourceMAC, String destinationMAC, String type, int lenght, String info, byte[] head,
			byte[] data, String version, int headLen, String ds, String id, int mf, int df, int fragmentOffset,
			int timeToLive, String protocol, String headerCheckNum, String sourceIP, String destinationIP) {
		super(sourceMAC, destinationMAC, type, lenght, info, head, data, sourceIP, destinationIP,protocol);
		this.version = version;
		this.headLen = headLen;
		this.ds = ds;
		this.id = id;
		this.mf = mf;
		this.df = df;
		this.fragmentOffset = fragmentOffset;
		this.timeToLive = timeToLive;
		this.headerCheckNum = headerCheckNum;
	}

	public MyIPv4Packet(MyIPv4Packet o) {
		this(o.getSourceMAC(), o.getDestinationMAC(), o.getType(), o.getLenght(), o.getInfo(), o.getHead(), o.getData(),
				o.getVersion(), o.getHeadLen(), o.getDs(), o.getId(), o.getMF(), o.getDF(), o.getFragmentOffset(),
				o.getTimeToLive(), o.getProtocol(), o.getHeaderCheckNum(), o.getSourceIP(), o.getDestinationIP());
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public int getHeadLen() {
		return headLen;
	}

	public void setHeadLen(int headLen) {
		this.headLen = headLen;
	}

	public String getDs() {
		return ds;
	}

	public void setDs(String ds) {
		this.ds = ds;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public int getMF() {
		return mf;
	}

	public void setMF(int mf) {
		this.mf = mf;
	}

	public int getDF() {
		return df;
	}

	public void setDF(int df) {
		this.df = df;
	}

	public int getFragmentOffset() {
		return fragmentOffset;
	}

	public void setFragmentOffset(int fragmentOffset) {
		this.fragmentOffset = fragmentOffset;
	}

	public int getTimeToLive() {
		return timeToLive;
	}

	public void setTimeToLive(int timeToLive) {
		this.timeToLive = timeToLive;
	}

	public String getHeaderCheckNum() {
		return headerCheckNum;
	}

	public void setHeaderCheckNum(String headerCheckNum) {
		this.headerCheckNum = headerCheckNum;
	}

	public String getSourceIP() {
		return sourceIP;
	}

	public void setSourceIP(String sourceIP) {
		this.sourceIP = sourceIP;
	}

	public String getDestinationIP() {
		return destinationIP;
	}

	public void setDestinationIP(String destinationIP) {
		this.destinationIP = destinationIP;
	}

	public CommonIPChildPacket getChildPacket() {
		return childPacket;
	}

	public void setChildPacket(CommonIPChildPacket childPacket) {
		this.childPacket = childPacket;
	}

	@Override
	public String getInfo() {
		if (childPacket != null) {
			return this.childPacket.getInfo();
		}
		return super.getInfo();
	}

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append(super.toString());
		sb.append(SystemUIControl.SPLITSTRING+"\n");
		sb.append("Version:" + this.version + "\n");
		sb.append("Header Length:" + this.headLen + "\n");
		sb.append("DS:" + this.ds + "\n");
		sb.append("Total Length:" + this.getLenght() + "\n");
		sb.append("ID:" + this.id + "\n");
		sb.append("MF:" + this.mf + "\n");
		sb.append("DF:" + this.df + "\n");
		sb.append("Fragment Offset:" + this.fragmentOffset + "\n");
		sb.append("Time To Live:" + this.timeToLive + "\n");
		sb.append("Protocol:" + this.protocol + "\n");
		sb.append("Header CheckNum:" + this.headerCheckNum + "\n");
		sb.append("SourceIP:" + this.sourceIP + "\n");
		sb.append("DestinationIP:" + this.destinationIP + "\n");
		if (this.childPacket != null) {
			sb.append(SystemUIControl.SPLITSTRING+"\n");
			sb.append(this.childPacket.toString());
		}
		return sb.toString();
	}
}
